A microprocessor can execute instructions at a very high rate, and it must be connected to a memory system in order to fetch the instructions. The typical memory system includes a large but relatively slow main system memory, and one or more cache memories.
A cache memory, or “cache”, is a relatively small and fast storage system incorporated either inside or close to a processor or between a processor and the main system memory. A cache memory stores instructions or data, which can be quickly supplied to the processor. The effectiveness of the cache is largely determined by the spatial locality and temporal locality properties of a program involved. Data from the much larger but slower main memory is automatically staged into the cache by special hardware on a demand basis.
When a memory read operation is requested by the processor, the cache memory is checked to determine whether or not the data is present in the cache memory. If the cache contains the referenced data, the cache provides the data to the processor. Otherwise, the data is further accessed from the main memory. Therefore, the cache can store frequently accessed information and improve the processor performance by delivering the needed information faster than the main memory. In a typical design, a cache memory uses a data array to store data and a tag array to store the tag addresses corresponding to the data.
A main memory address may include a tag field and an index field. The index field is used to index a specific tag address stored in the cache tag array. When a cache memory access is performed, the tag address stored in the cache tag array is read and it is then compared to the tag field of the main memory address. If the two tag addresses match, a cache “hit” has occurred and the corresponding data is read out from the cache to the processor. If the two tag addresses do not match, a cache “miss” has occurred and the requested data is not in the cache, and must be retrieved from other components such as the main memory.